module.exports = function($scope, $modal, $resource, toaster){
    
    $scope.load = function(){
        $resource('/api/as/puc/subsidycount/getCompanyLimitList', {}, {}).save({}, function(res){
            if(res.errcode === 0){
				$scope.list = res.data;
            } else {
                toaster.error({title: '', body: '获取列表失败'});
            }
        });
	};
	$scope.load();


	//添加企业限额信息
    $scope.addCompany = function(){
    	var modalInstance = $modal.open({
			template: require('../views/companylimitinfo.html'),
			controller: 'companylimitinfo',
			size: 'lg',
			resolve: {
				companyinfo: function () {
					return null;
				}
			}
		});
		modalInstance.result.then(function(result){
			$scope.load();
		});
	};

    $scope.setMoney = function(obj){
    	var modalInstance = $modal.open({
			template: require('../views/companylimitinfo.html'),
			controller: 'companylimitinfo',
			size: 'lg',
			resolve: {
				companyinfo: function () {
					return obj;
				}
			}
		});
		modalInstance.result.then(function(result){
			obj.uplimit_money = result * 100;
		});
	};

	$scope.delete = function(id, index){
    	if(confirm('确认删除此企业的补贴限额信息吗？')){
			var para = {
				'id': id
			}
			$resource('/api/as/puc/subsidycount/deleteCompanyLimit', {}, {}).save(para, function(res){
				if(res.errcode === 0){
					toaster.success({title: '', body: '删除成功'});
					$scope.list.splice(index, 1);
				} else {
					toaster.error({title: '', body: '删除失败'});
				}
			});
		}
	};
	

};